package com.approval.approvalapp.index.dbsx.ptbl.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.approval.approvalapp.R;
import com.approval.approvalapp.bean.PtblXqBean;
import com.approval.approvalapp.bean.SbclckBean;
import com.approval.approvalapp.index.dbsx.ptbl.adapter.PtblxqAdapter;
import com.approval.approvalapp.util.SpUtil;
import com.approval.approvalapp.util.base.BaseActivity;
import com.approval.approvalapp.util.base.BaseFragment;
import com.approval.approvalapp.util.base.SbclckActivity;
import com.approval.approvalapp.util.base.YwSjCkActivity;
import com.approval.approvalapp.util.net.NetRequsetUtil;
import com.approval.approvalapp.util.net.interfacepac.NetDownResponse;
import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;

public class PtblXqYbActivity extends BaseActivity {
    @Bind(R.id.back_iv)
    ImageView backIv;
    @Bind(R.id.titleTv1)
    TextView titleTv1;
    @Bind(R.id.color_civ)
    CircleImageView colorCiv;
    @Bind(R.id.sqr_tv)
    TextView sqrTv;
    @Bind(R.id.sbsx_tv)
    TextView sbsxTv;
    @Bind(R.id.sbsj_tv)
    TextView sbsjTv;
    @Bind(R.id.blsx_tv)
    TextView blsxTv;
    @Bind(R.id.lxdh_tv)
    TextView lxdhTv;
    @Bind(R.id.zjlx_tv)
    TextView zjlxTv;
    @Bind(R.id.zjhm_tv)
    TextView zjhmTv;
    @Bind(R.id.zk_tv)
    TextView zkTv;
    @Bind(R.id.zk_iv)
    ImageView zkIv;
    @Bind(R.id.zk_ll)
    LinearLayout zkLl;
    @Bind(R.id.rv)
    RecyclerView rv;
    @Bind(R.id.name_tv)
    TextView name_tv;
    @Bind(R.id.current_node_name_tv)
    TextView current_node_name_tv;
    @Bind(R.id.ywsjck_ll)
    LinearLayout ywsjck_ll;

    private String business_object_code;
    private String business_object_type;
    private String item_id;
    private String bsnum;
    private String sbsx;
    private String blsx;
    private String sbsj;
    private String sqr;
    private boolean zk = false;//默认是隐藏
    private PtblxqAdapter ptblxqAdapter;
    private List<PtblXqBean.BlyjShowBean> blyj_show;
    private PtblXqBean ptblXqBean;


    @Override
    public int getLayoutId() {
        return R.layout.activity_ptbl_xq_yb;
    }

    @Override
    public void initView() {
        //下面几个是接口参数
        business_object_code = getIntent().getStringExtra("business_object_code");
        business_object_type = getIntent().getStringExtra("business_object_type");
        item_id = getIntent().getStringExtra("item_id");
        bsnum = getIntent().getStringExtra("bsnum");
        //申报事项
        sbsx = getIntent().getStringExtra("sbsx");
        //办理事项
        blsx = getIntent().getStringExtra("blsx");
        //申报时间
        sbsj = getIntent().getStringExtra("sbsj");
        //申请人姓名
        sqr = getIntent().getStringExtra("sqr");

        //先展示缓存能展示的数据
        titleTv1.setText("审批办理");
        name_tv.setText("审批人: " + SpUtil.getString(this,SpUtil.USER_RUN_NICKNAME,""));
        sbsxTv.setText(sbsx);
        sqrTv.setText("申请人: " + sqr);
        sbsjTv.setText("申报时间: " + sbsj);
        blsxTv.setText(blsx);
    }



    @Override
    public void initData() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("business_object_code",business_object_code);
        jsonObject.put("business_object_type",business_object_type);
        jsonObject.put("item_id",item_id);
        jsonObject.put("bsnum",bsnum);
        NetRequsetUtil.getInstance().netRequestPostJson("v1/user/piece_shows",jsonObject.toString() , new NetDownResponse() {
            @Override
            public void success(String str) {
                ptblXqBean = JSON.parseObject(str, PtblXqBean.class);
                lxdhTv.setText(ptblXqBean.getLink_phone());
                zjlxTv.setText(ptblXqBean.getIdentity_type());
                zjhmTv.setText(ptblXqBean.getIdcard_no());
                ptblxqAdapter = new PtblxqAdapter();
                blyj_show = ptblXqBean.getBlyj_show();
                ptblxqAdapter.setBlyjShowBeanList(blyj_show);
                rv.setLayoutManager(new LinearLayoutManager(PtblXqYbActivity.this));
                rv.setAdapter(ptblxqAdapter);
            }

            @Override
            public void errowithresponse(String str) {

            }

            @Override
            public void erro() {

            }

            @Override
            public void finish() {

            }
        });

    }

    @OnClick({R.id.back_iv,R.id.zk_ll,R.id.ywsjck_ll,R.id.sbclck_ll
            })
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_iv:
                finish();
                break;
            case R.id.commit_tv:
                break;
            case R.id.zk_ll:
                if (zk){
                    //收起
                    rv.setVisibility(View.GONE);
                    zkTv.setText("展开");
                    zkIv.setBackgroundResource(R.drawable.unfold);
                    zk = false;
                }else {
                    //展开
                    rv.setVisibility(View.VISIBLE);
                    ptblxqAdapter = new PtblxqAdapter();
                    ptblxqAdapter.setBlyjShowBeanList(blyj_show);
                    rv.setLayoutManager(new LinearLayoutManager(this));
                    rv.setAdapter(ptblxqAdapter);
                    zkTv.setText("收起");
                    zkIv.setBackgroundResource(R.drawable.packup);
                    zk = true;
                }
                break;
            case R.id.ywsjck_ll:
                YwSjCkActivity.goInto(this,blsxTv.getText().toString(),
                        sqrTv.getText().toString(),lxdhTv.getText().toString(),
                        zjlxTv.getText().toString(), zjhmTv.getText().toString());
                break;
            case R.id.sbclck_ll:
                List<SbclckBean> sbclckBeanList = new ArrayList<>();
                if (ptblXqBean == null){
                    return;
                }
                for (int i = 0; i <ptblXqBean.getMaterial().size() ; i++) {
                    sbclckBeanList.add(new SbclckBean(ptblXqBean.getMaterial().get(i).getFILE_NAME(),
                            ptblXqBean.getMaterial().get(i).getFILE_PATH(),
                            ptblXqBean.getMaterial().get(i).getFILE_URL()));
                }
                SbclckActivity.goInto(this,sbclckBeanList);
                break;
        }
    }
}
